﻿class Solution {
public:
    bool backspaceCompare(string s, string t) {
        return str(s) == str(t);
    }

    string str(string s)
    {
        string ret;
        for (auto ch : s)
        {
            if (ch != '#') ret += ch;
            else {
                if (ret.size()) ret.pop_back();
            }
        }
        return ret;
    }
};